package com.damai.action;

import java.util.List;
import java.util.Map;

import com.citywithincity.api.ApiBuildUtil;
import com.damai.action.aop.Interceptor;

import javassist.ClassClassPath;
import javassist.ClassPool;

public class Actions {
	private Map<String, IAction> actionMap;
	private List<Interceptor> interceptors;
	ClassPool classPool;
	public Actions(ClassPool classPool,Map<String, IAction> actionMap,List<Interceptor> interceptors){
		this.actionMap = actionMap;
		this.interceptors = interceptors;
		this.classPool = classPool;
	}

	
	public void add(IAction action){
		actionMap.put(action.getKey(), action);
	}
	
	public void add(Class<?> controllerClass){
		try {
			this.classPool.appendClassPath(new ClassClassPath(controllerClass));
			ApiBuildUtil.helpBuildAction(classPool,controllerClass, actionMap,interceptors);
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}
	
}
